package _动态规划系列._股票买卖问题;

/**
 * @Author: 吕庆龙
 * @Date: 2020/3/31 16:46
 * <p>
 * 功能描述:
 */
public class Summary_0714 {


    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[][] dp = new int[n][2];

        //base case
        dp[0][0] = 0;
        dp[0][1] = -prices[0] - fee;

        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i]);
            dp[i][1] = Math.max(dp[i - 1][1], dp[i - 1][0] - prices[i] - fee);
        }

        return dp[n-1][0];
    }
}
